package com.fulihui.information.biz.conv;

import com.fulihui.information.dal.dataobj.InfoContentCommentsReply;
import com.fulihui.information.dto.InfoContentCommentsReplyDTO;
import org.apache.commons.codec.binary.Base64;

import java.util.List;
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static org.springframework.util.CollectionUtils.isEmpty;

/**
 * Created by LM on 2017/4/9.
 */
public class ContentCommentsReplyConv {

    public static InfoContentCommentsReplyDTO toDTO(InfoContentCommentsReply entity) {
        if (entity == null) {
            return null;
        }
        InfoContentCommentsReplyDTO dto = new InfoContentCommentsReplyDTO();
        dto.setUserName(entity.getUserName());
        dto.setUserId(entity.getUserId());
        dto.setUserPic(entity.getUserPic());
        dto.setGmtCreate(entity.getGmtCreate());
        dto.setCommentId(entity.getCommentId());
        dto.setStorey(entity.getStorey());
        dto.setContentTitle(entity.getContentTitle());
        dto.setContentId(entity.getContentId());
        dto.setId(entity.getId());
        dto.setOperator(entity.getOperator());
        dto.setReplyContent(new String(Base64.decodeBase64(entity.getReplyContent())));
        dto.setStatus(entity.getStatus());
        dto.setToUserId(entity.getToUserId());
        dto.setToUserName(entity.getToUserName());
        dto.setToUserPic(entity.getToUserPic());
        dto.setGmtModified(entity.getGmtModified());
        dto.setReplyId(entity.getReplyId());
        return dto;
    }

    public static List<InfoContentCommentsReplyDTO> toDTOList(List<InfoContentCommentsReply> list) {
        if (isEmpty(list)) {
            return emptyList();
        }
        return list.stream().map(it -> toDTO(it)).collect(Collectors.toList());
    }

}
